﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>修改日志</title>

    <link href="css/blog_update.css" rel="stylesheet" type="text/css">
    <script src="/js/axios.min.js"></script>
    <script src="/js/vue.min.js"></script>
</head>

<body>
<div id="entrydiv">
    <div id="head">
    </div>


    <div id="body">
        <h1>修改日志</h1>
        <p>日志标题 *
            <span><!--<input name="" type="button" value="保存"/> -->
<input name="" type="button" @click="updateEntry()" value="修 改"/>
<input name="9" type="button" value="返回"/></span></p>
        <p>
            <input name="" type="text" class="t_input" v-model="title"/>
            <input type="hidden" class="t_input" v-model="id"/>
        </p>
        <p>发布时间 *</p>
        <p><input name="" type="Date" v-model="modifytime"/></p>
        <p>日志分类 *</p>
        <p><!--<input name="" type="checkbox" value=""  v-model="categoryid"/>Java-->
            <select v-model="categoryid">
                <option v-for="category in categoryList" :value="category.id">{{category.name}}</option>
            </select>
        </p>
        <p>日志内容 *</p>
        <p><textarea name="" cols="80" rows="12" v-model="content"></textarea></p>
        <p>日志摘要</p>
        <p><textarea name="" cols="80" rows="8" v-model="summary"></textarea></p>
        <p><input name="" type="button" @click="updateEntry()" value="修 改"/>
            <!-- <input name="" type="button" value="发 布"/>--></p>
    </div>

    <div id="foot">
        <hr/>
        <center>Copyright &copy; 2013-2020</center>
    </div>
</div>
<script type="text/javascript">
    var vm = new Vue({
        el: "#entrydiv",
        data: {
            id: '',
            title: '',
            modifytime: '',
            content: '',
            summary: '',
            categoryid: 0,
            categoryList: ''
        },
        created() {
            //初始化的时候加载
            this.category();
            this.findEntryById();
        },
        methods: {
            findEntryById:function(){
                axios.get("findEntryById2",null).then(function (obj) {
                    if(obj.status==200){
                        var entry = obj.data.result;
                        vm.id = entry.id;
                        vm.title = entry.title;
                        vm.modifytime = entry.modifytime;
                        vm.content = entry.content;
                        vm.summary = entry.summary;
                        vm.categoryid = entry.categoryid;
                        //alert("查询成功");
                    }
                }).catch(function () {

                })
            },
            updateEntry: function () {
                var path = "/Entry";
                var param = {
                    id: vm.id,
                    title: vm.title,
                    modifytime: vm.modifytime,
                    content: vm.content,
                    summary: vm.summary,
                    categoryid: vm.categoryid
                };
                axios.put(path, param).then(function (obj) {
                    if (obj.status == 200) {
                        var pageResult = obj.data;
                        alert(pageResult.msg);
                    }
                }).catch(function () {
                    //有问题函数
                    alert("修改错误")
                });
            },
            category: function () {
                var path = "/Category";
                axios.get(path, null).then(function (obj) {
                    if (obj.status == 200) {
                        var pageResult = obj.data;
                        vm.categoryList = pageResult.result;
                    }
                }).catch(function () {
                    //有问题函数
                    alert("初始化错误")
                });
            }

        }
    });
</script>
</body>
</html>
